<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Object example:person</title>
    </head>
    <body>
    </body>
    <script>

        let person = {
            name: "Tom Jerry",
            name2: {
                first: "Tom",
                last: "Jerry",
            },
            age: 19,
            interests: ['music', 'skiing'],
            info: function () {
                console.log(this.name + "  " + this.age + "  " + this.interests[0] + "  " + this.interests[1]);
            }
        };

        //点表示法:访问对象的属性和方法
        person.name;
        person.age;
        person.interests[1];
        person.info();
        person.name2.first;

        // 括号表示法:访问属性
        person["name"];
        person["age"];
        person["interests"][1];
        person["name2"]["first"];

        // 设置对象成员
        // 访问对象的已有成员
        person.age = 20;
        person["name2"]["first"] = 'Tome A';
        // 创建新的成员
        person.eyes1 = 'hazel';
        person['eyes2'] = 'hazel';
        person.farewell_1 = function () {
            console.log("Bye everybody!")
        };
        person["farewell_2"] = function () {
            console.log("Bye everybody!")
        };
        let myDataName = "height";
        let myDataValue = "1.75m";
        // 变量作为名字
        person[myDataName] = myDataValue;
        person.height;

        // this
        let person2 = {
            name: "Wiki Hao",
            name2: {
                first: "Wiki",
                last: "Hao",
            },
            age: 10,
            interests: ['swim', 'game'],
            info: function () {
                console.log(this.name + "  " + this.age + "  " + this.interests[0] + "  " + this.interests[1]);
            }
        };
        person.info();  // Tom Jerry  20  music  skiing
        person2.info(); // Wiki Hao  10  swim  game

    </script>
</html>